import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();

        Thread t1 = new Thread(){
            @Override
            public void run() {
                while(true) {
                    try {
                        int a = queue.take();
                        System.out.println("消费了: "+a);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {
                for (int i = 1; i <= 10; i++) {
                    try {
                        queue.put(i);
                        System.out.println("生产了: "+i);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t2.start();
        t1.start();

        t1.join();
        t2.join();
    }
}
